from selenium.webdriver.common.by import By
from pages.base_page import Page
import time


class AgentWrapupPage(Page):
    ele_page_title = (By.XPATH, u"//h3[text()='Agent Wrap-up']")
    ele_page_feature_introduction_title = (By.XPATH, u"//h3[text()='Feature Introduction']")
    ele_add_a_field = (By.XPATH, u"//span[text()='Add a Field']")
    ele_field_name = (By.XPATH, u"//div[@data-formfield='field']")
    ele_new_field = (By.XPATH, u"//a[text()='+ New Field']")
    ele_drawer_title = (By.XPATH, u"//h3[text()='New Field']")
    ele_drawer_field_name = (By.XPATH, u"//div[@data-formfield='name']")
    ele_drawer_button_save = (By.XPATH, u"//span[text()='Save' and contains(@class, 'Drawer')]")
    ele_button_save = (By.XPATH, u"//span[text()='Save']")
    ele_button_chat_with_us = (By.XPATH, u"//span[text()='Chat with us']")

    # dataTable
    data_table = (By.XPATH, u"//table")

    cfield_name = str(round(time.time() * 1000))

    def __init__(self, driver, url, site_id):
        Page.__init__(self, driver, url)
        self.site_id = site_id
        self.url = url

    def agent_wrapup_page_eles_check_with_wrapup_feature(self):
        self.find_element(*self.ele_page_title).is_enabled()
        self.find_element(*self.ele_add_a_field).is_enabled()

    def agent_wrapup_page_eles_check_without_wrapup_feature(self):
        self.find_element(*self.ele_page_title).is_enabled()
        self.find_element(*self.ele_page_feature_introduction_title).is_enabled()
        self.find_element(*self.ele_button_chat_with_us).is_enabled()

    def agent_wrapup_page_add_a_field_with_wrapup_feature(self):
        self.click(self.ele_add_a_field)
        self.find_element(*self.ele_field_name).is_enabled()
        self.click(self.ele_field_name)
        self.find_element(*self.ele_new_field).is_enabled()
        self.click(self.ele_new_field)
        self.find_element(*self.ele_drawer_title).is_enabled()
        self.click(self.ele_drawer_field_name)
        self.ele_drawer_field_name.send_keys(self.cfield_name)
        self.input_text(self.ele_drawer_field_name, self.cfield_name)
        self.click(self.ele_drawer_button_save)
        self.click(self.ele_button_save)
